home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_perl.idb / usr / freeware / catman / u_man / cat1 / perlfaq8.Z / perlfaq8
Encoding:
Text File  |  1998-10-28  |  61.3 KB  |  1,519 lines

  1.  
  2.  
  3.  
  4.      PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))      5555////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.       perlfaq8 - System Interaction    ($Revision: 1.26 $, $Date:
  10.       1998/08/05 12:20:28 $)
  11.  
  12.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  13.       This section of the Perl FAQ covers questions    involving
  14.       operating system interaction.     This involves interprocess
  15.       communication    (IPC), control over the    user-interface
  16.       (keyboard, screen and    pointing devices), and most anything
  17.       else not related to data manipulation.
  18.  
  19.       Read the FAQs    and documentation specific to the port of perl
  20.       to your operating system (eg,    the _p_e_r_l_v_m_s manpage, the
  21.       _p_e_r_l_p_l_a_n_9 manpage, ...).  These should contain more detailed
  22.       information on the vagaries of your perl.
  23.  
  24.       HHHHoooowwww ddddoooo IIII ffffiiiinnnndddd    oooouuuutttt wwwwhhhhiiiicccchhhh ooooppppeeeerrrraaaattttiiiinnnngggg ssssyyyysssstttteeeemmmm IIII''''mmmm rrrruuuunnnnnnnniiiinnnngggg uuuunnnnddddeeeerrrr????
  25.  
  26.       The $^O variable ($OSNAME if you use English)    contains the
  27.       operating system that    your perl binary was built for.
  28.  
  29.       HHHHoooowwww ccccoooommmmeeee _e_x_e_c() doesn't return?
  30.  
  31.       Because that's what it does: it replaces your    currently
  32.       running program with a different one.     If you    want to    keep
  33.       going    (as is probably    the case if you're asking this
  34.       question) use    _s_y_s_t_e_m() instead.
  35.  
  36.       HHHHoooowwww ddddoooo IIII ddddoooo ffffaaaannnnccccyyyy ssssttttuuuuffffffff wwwwiiiitttthhhh tttthhhheeee kkkkeeeeyyyybbbbooooaaaarrrrdddd////ssssccccrrrreeeeeeeennnn////mmmmoooouuuusssseeee????
  37.  
  38.       How you access/control keyboards, screens, and pointing
  39.       devices ("mice") is system-dependent.     Try the following
  40.       modules:
  41.  
  42.       Keyboard
  43.  
  44.           Term::Cap              Standard perl distribution
  45.           Term::ReadKey              CPAN
  46.           Term::ReadLine::Gnu          CPAN
  47.           Term::ReadLine::Perl          CPAN
  48.           Term::Screen              CPAN
  49.  
  50.  
  51.       Screen
  52.  
  53.           Term::Cap              Standard perl distribution
  54.           Curses              CPAN
  55.           Term::ANSIColor          CPAN
  56.  
  57.  
  58.       Mouse
  59.  
  60.  
  61.  
  62.  
  63.      Page 1                        (printed 10/23/98)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))      5555////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))
  71.  
  72.  
  73.  
  74.           Tk                  CPAN
  75.  
  76.  
  77.       Some of these    specific cases are shown below.
  78.  
  79.       HHHHoooowwww ddddoooo IIII pppprrrriiiinnnntttt ssssoooommmmeeeetttthhhhiiiinnnngggg oooouuuutttt iiiinnnn ccccoooolllloooorrrr????
  80.  
  81.       In general, you don't, because you don't know    whether    the
  82.       recipient has    a color-aware display device.  If you know
  83.       that they have an ANSI terminal that understands color, you
  84.       can use the Term::ANSIColor module from CPAN:
  85.  
  86.           use Term::ANSIColor;
  87.           print color("red"), "Stop!\n", color("reset");
  88.           print color("green"), "Go!\n", color("reset");
  89.  
  90.       Or like this:
  91.  
  92.           use Term::ANSIColor qw(:constants);
  93.           print RED, "Stop!\n", RESET;
  94.           print GREEN, "Go!\n", RESET;
  95.  
  96.  
  97.       HHHHoooowwww ddddoooo IIII rrrreeeeaaaadddd    jjjjuuuusssstttt oooonnnneeee kkkkeeeeyyyy wwwwiiiitttthhhhoooouuuutttt wwwwaaaaiiiittttiiiinnnngggg ffffoooorrrr aaaa rrrreeeettttuuuurrrrnnnn kkkkeeeeyyyy????
  98.  
  99.       Controlling input buffering is a remarkably system-dependent
  100.       matter.  If most systems, you    can just use the ssssttttttttyyyy command
  101.       as shown in the getc entry in    the _p_e_r_l_f_u_n_c manpage, but as
  102.       you see, that's already getting you into portability snags.
  103.  
  104.           open(TTY,    "+</dev/tty") or die "no tty: $!";
  105.           system "stty  cbreak </dev/tty >/dev/tty 2>&1";
  106.           $key = getc(TTY);          # perhaps this works
  107.           #    OR ELSE
  108.           sysread(TTY, $key, 1);      # probably this does
  109.           system "stty -cbreak </dev/tty >/dev/tty 2>&1";
  110.  
  111.       The Term::ReadKey module from    CPAN offers an easy-to-use
  112.       interface that should    be more    efficient than shelling    out to
  113.       ssssttttttttyyyy for each    key.  It even includes limited support for
  114.       Windows.
  115.  
  116.           use Term::ReadKey;
  117.           ReadMode('cbreak');
  118.           $key = ReadKey(0);
  119.           ReadMode('normal');
  120.  
  121.       However, that    requires that you have a working C compiler
  122.       and can use it to build and install a    CPAN module.  Here's a
  123.       solution using the standard POSIX module, which is already
  124.       on your systems (assuming your system    supports POSIX).
  125.  
  126.  
  127.  
  128.  
  129.      Page 2                        (printed 10/23/98)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))      5555////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))
  137.  
  138.  
  139.  
  140.           use HotKey;
  141.           $key = readkey();
  142.  
  143.       And here's the HotKey    module,    which hides the    somewhat
  144.       mystifying calls to manipulate the POSIX termios structures.
  145.  
  146.           #    HotKey.pm
  147.           package HotKey;
  148.  
  149.           @ISA = qw(Exporter);
  150.           @EXPORT =    qw(cbreak cooked readkey);
  151.  
  152.           use strict;
  153.           use POSIX    qw(:termios_h);
  154.           my ($term, $oterm, $echo,    $noecho, $fd_stdin);
  155.  
  156.           $fd_stdin    = fileno(STDIN);
  157.           $term    = POSIX::Termios->new();
  158.           $term->getattr($fd_stdin);
  159.           $oterm     = $term->getlflag();
  160.  
  161.           $echo    = ECHO | ECHOK | ICANON;
  162.           $noecho    = $oterm & ~$echo;
  163.  
  164.           sub cbreak {
  165.           $term->setlflag($noecho);  # ok, so i    don't want echo    either
  166.           $term->setcc(VTIME, 1);
  167.           $term->setattr($fd_stdin, TCSANOW);
  168.           }
  169.  
  170.           sub cooked {
  171.           $term->setlflag($oterm);
  172.           $term->setcc(VTIME, 0);
  173.           $term->setattr($fd_stdin, TCSANOW);
  174.           }
  175.  
  176.           sub readkey {
  177.           my $key = '';
  178.           cbreak();
  179.           sysread(STDIN, $key, 1);
  180.           cooked();
  181.           return $key;
  182.           }
  183.  
  184.           END { cooked() }
  185.  
  186.           1;
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.      Page 3                        (printed 10/23/98)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))      5555////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))
  203.  
  204.  
  205.  
  206.       HHHHoooowwww ddddoooo IIII cccchhhheeeecccckkkk wwwwhhhheeeetttthhhheeeerrrr iiiinnnnppppuuuutttt iiiissss rrrreeeeaaaaddddyyyy    oooonnnn tttthhhheeee kkkkeeeeyyyybbbbooooaaaarrrrdddd????
  207.  
  208.       The easiest way to do    this is    to read    a key in nonblocking
  209.       mode with the    Term::ReadKey module from CPAN,    passing    it an
  210.       argument of -1 to indicate not to block:
  211.  
  212.           use Term::ReadKey;
  213.  
  214.           ReadMode('cbreak');
  215.  
  216.           if (defined ($char = ReadKey(-1))    ) {
  217.           # input was waiting and it was $char
  218.           }    else {
  219.           # no input was waiting
  220.           }
  221.  
  222.           ReadMode('normal');           # restore normal tty    settings
  223.  
  224.  
  225.       HHHHoooowwww ddddoooo IIII cccclllleeeeaaaarrrr tttthhhheeee ssssccccrrrreeeeeeeennnn????
  226.  
  227.       If you only have to so infrequently, use system:
  228.  
  229.           system("clear");
  230.  
  231.       If you have to do this a lot,    save the clear string so you
  232.       can print it 100 times without calling a program 100 times:
  233.  
  234.           $clear_string = `clear`;
  235.           print $clear_string;
  236.  
  237.       If you're planning on    doing other screen manipulations, like
  238.       cursor positions, etc, you might wish    to use Term::Cap
  239.       module:
  240.  
  241.           use Term::Cap;
  242.           $terminal    = Term::Cap->Tgetent( {OSPEED => 9600} );
  243.           $clear_string = $terminal->Tputs('cl');
  244.  
  245.  
  246.       HHHHoooowwww ddddoooo IIII ggggeeeetttt tttthhhheeee ssssccccrrrreeeeeeeennnn ssssiiiizzzzeeee????
  247.  
  248.       If you have Term::ReadKey module installed from CPAN,    you
  249.       can use it to    fetch the width    and height in characters and
  250.       in pixels:
  251.  
  252.           use Term::ReadKey;
  253.           ($wchar, $hchar, $wpixels, $hpixels) = GetTerminalSize();
  254.  
  255.       This is more portable    than the raw ioctl, but    not as
  256.       illustrative:
  257.  
  258.  
  259.  
  260.  
  261.      Page 4                        (printed 10/23/98)
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.      PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))      5555////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))
  269.  
  270.  
  271.  
  272.           require 'sys/ioctl.ph';
  273.           die "no TIOCGWINSZ " unless defined &TIOCGWINSZ;
  274.           open(TTY,    "+</dev/tty")              or die "No tty: $!";
  275.           unless (ioctl(TTY, &TIOCGWINSZ, $winsize='')) {
  276.           die sprintf "$0: ioctl TIOCGWINSZ (%08x: $!)\n", &TIOCGWINSZ;
  277.           }
  278.           ($row, $col, $xpixel, $ypixel) = unpack('S4', $winsize);
  279.           print "(row,col) = ($row,$col)";
  280.           print "  (xpixel,ypixel) = ($xpixel,$ypixel)" if $xpixel || $ypixel;
  281.           print "\n";
  282.  
  283.  
  284.       HHHHoooowwww ddddoooo IIII aaaasssskkkk tttthhhheeee uuuusssseeeerrrr    ffffoooorrrr aaaa ppppaaaasssssssswwwwoooorrrrdddd????
  285.  
  286.       (This    question has nothing to    do with    the web.  See a
  287.       different FAQ    for that.)
  288.  
  289.       There's an example of    this in    the crypt entry    in the
  290.       _p_e_r_l_f_u_n_c manpage).  First, you put the terminal into "no
  291.       echo"    mode, then just    read the password normally.  You may
  292.       do this with an old-style _i_o_c_t_l() function, POSIX terminal
  293.       control (see the _P_O_S_I_X manpage, and Chapter 7    of the Camel),
  294.       or a call to the ssssttttttttyyyy    program, with varying degrees of
  295.       portability.
  296.  
  297.       You can also do this for most    systems    using the
  298.       Term::ReadKey    module from CPAN, which    is easier to use and
  299.       in theory more portable.
  300.  
  301.           use Term::ReadKey;
  302.  
  303.           ReadMode('noecho');
  304.           $password    = ReadLine(0);
  305.  
  306.  
  307.       HHHHoooowwww ddddoooo IIII rrrreeeeaaaadddd    aaaannnndddd wwwwrrrriiiitttteeee tttthhhheeee sssseeeerrrriiiiaaaallll ppppoooorrrrtttt????
  308.  
  309.       This depends on which    operating system your program is
  310.       running on.  In the case of Unix, the    serial ports will be
  311.       accessible through files in /dev; on other systems, the
  312.       devices names    will doubtless differ.    Several    problem    areas
  313.       common to all    device interaction are the following
  314.  
  315.       lockfiles
  316.           Your system may use lockfiles to control multiple
  317.           access.  Make sure you follow the    correct    protocol.
  318.           Unpredictable behaviour can result from multiple
  319.           processes    reading    from one device.
  320.  
  321.       open mode
  322.           If you expect to use both    read and write operations on
  323.           the device, you'll have to open it for update (see the
  324.  
  325.  
  326.  
  327.      Page 5                        (printed 10/23/98)
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.      PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))      5555////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))
  335.  
  336.  
  337.  
  338.           section on _o_p_e_n in the _p_e_r_l_f_u_n_c manpage for details).
  339.           You may wish to open it without running the risk of
  340.           blocking by using    _s_y_s_o_p_e_n() and O_RDWR|O_NDELAY|O_NOCTTY
  341.           from the Fcntl module (part of the standard perl
  342.           distribution).  See the section on _s_y_s_o_p_e_n in the
  343.           _p_e_r_l_f_u_n_c manpage for more    on this    approach.
  344.  
  345.       end of line
  346.           Some devices will    be expecting a "\r" at the end of each
  347.           line rather than a "\n".    In some    ports of perl, "\r"
  348.           and "\n" are different from their    usual (Unix) ASCII
  349.           values of    "\012" and "\015".  You    may have to give the
  350.           numeric values you want directly,    using octal ("\015"),
  351.           hex ("0x0D"), or as a control-character specification
  352.           ("\cM").
  353.  
  354.           print    DEV "atv1\012";          #    wrong, for some    devices
  355.           print    DEV "atv1\015";          #    right, for some    devices
  356.  
  357.           Even though with normal text files, a "\n" will do the
  358.           trick, there is still no unified scheme for terminating
  359.           a    line that is portable between Unix, DOS/Win, and
  360.           Macintosh, except    to terminate _A_L_L line ends with
  361.           "\015\012", and strip what you don't need    from the
  362.           output.  This applies especially to socket I/O and
  363.           autoflushing, discussed next.
  364.  
  365.       flushing output
  366.           If you expect characters to get to your device when you
  367.           _p_r_i_n_t() them, you'll want    to autoflush that filehandle.
  368.           You can use _s_e_l_e_c_t() and the $| variable to control
  369.           autoflushing (see    the section on $| in the _p_e_r_l_v_a_r
  370.           manpage and the select entry in the _p_e_r_l_f_u_n_c manpage):
  371.  
  372.           $oldh    = select(DEV);
  373.           $| = 1;
  374.           select($oldh);
  375.  
  376.           You'll also see code that    does this without a temporary
  377.           variable,    as in
  378.  
  379.           select((select(DEV), $| = 1)[0]);
  380.  
  381.           Or if you    don't mind pulling in a    few thousand lines of
  382.           code just    because    you're afraid of a little $| variable:
  383.  
  384.           use IO::Handle;
  385.           DEV->autoflush(1);
  386.  
  387.           As mentioned in the previous item, this still doesn't
  388.           work when    using socket I/O between Unix and Macintosh.
  389.           You'll need to hardcode your line    terminators, in    that
  390.  
  391.  
  392.  
  393.      Page 6                        (printed 10/23/98)
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.      PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))      5555////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))
  401.  
  402.  
  403.  
  404.           case.
  405.  
  406.       non-blocking input
  407.           If you are doing a blocking _r_e_a_d() or _s_y_s_r_e_a_d(), you'll
  408.           have to arrange for an alarm handler to provide a
  409.           timeout (see the alarm entry in the _p_e_r_l_f_u_n_c manpage).
  410.           If you have a non-blocking open, you'll likely have a
  411.           non-blocking read, which means you may have to use a 4-
  412.           arg _s_e_l_e_c_t() to determine    whether    I/O is ready on    that
  413.           device (see the section on _s_e_l_e_c_t    in the _p_e_r_l_f_u_n_c
  414.           manpage.
  415.  
  416.       While    trying to read from his    caller-id box, the notorious
  417.       Jamie    Zawinski <jwz@netscape.com>, after much    gnashing of
  418.       teeth    and fighting with sysread, sysopen, POSIX's tcgetattr
  419.       business, and    various    other functions    that go    bump in    the
  420.       night, finally came up with this:
  421.  
  422.           sub open_modem {
  423.           use IPC::Open2;
  424.           my $stty = `/bin/stty    -g`;
  425.           open2( \*MODEM_IN, \*MODEM_OUT, "cu -l$modem_device -s2400 2>&1");
  426.           # starting cu    hoses /dev/tty's stty settings,    even when it has
  427.           # been opened    on a pipe...
  428.           system("/bin/stty $stty");
  429.           $_ = <MODEM_IN>;
  430.           chop;
  431.           if ( !m/^Connected/ )    {
  432.               print STDERR "$0:    cu printed `$_'    instead    of `Connected'\n";
  433.           }
  434.           }
  435.  
  436.  
  437.       HHHHoooowwww ddddoooo IIII ddddeeeeccccooooddddeeee eeeennnnccccrrrryyyypppptttteeeedddd ppppaaaasssssssswwwwoooorrrrdddd ffffiiiilllleeeessss????
  438.  
  439.       You spend lots and lots of money on dedicated    hardware, but
  440.       this is bound    to get you talked about.
  441.  
  442.       Seriously, you can't if they are Unix    password files - the
  443.       Unix password    system employs one-way encryption.  It's more
  444.       like hashing than encryption.     The best you can check    is
  445.       whether something else hashes    to the same string.  You can't
  446.       turn a hash back into    the original string.  Programs like
  447.       Crack    can forcibly (and intelligently) try to    guess
  448.       passwords, but don't (can't) guarantee quick success.
  449.  
  450.       If you're worried about users    selecting bad passwords, you
  451.       should proactively check when    they try to change their
  452.       password (by modifying _p_a_s_s_w_d(1), for    example).
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.      Page 7                        (printed 10/23/98)
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.      PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))      5555////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))
  467.  
  468.  
  469.  
  470.       HHHHoooowwww ddddoooo IIII ssssttttaaaarrrrtttt aaaa pppprrrroooocccceeeessssssss iiiinnnn tttthhhheeee bbbbaaaacccckkkkggggrrrroooouuuunnnndddd????
  471.  
  472.       You could use
  473.  
  474.           system("cmd &")
  475.  
  476.       or you could use fork    as documented in the section on    _f_o_r_k
  477.       in the _p_e_r_l_f_u_n_c manpage, with    further    examples in the
  478.       _p_e_r_l_i_p_c manpage.  Some things    to be aware of,    if you're on a
  479.       Unix-like system:
  480.  
  481.       STDIN, STDOUT, and STDERR are    shared
  482.           Both the main process and    the backgrounded one (the
  483.           "child" process) share the same STDIN, STDOUT and    STDERR
  484.           filehandles.  If both try    to access them at once,
  485.           strange things can happen.  You may want to close    or
  486.           reopen these for the child.  You can get around this
  487.           with opening a pipe (see the section on _o_p_e_n in the
  488.           _p_e_r_l_f_u_n_c manpage)    but on some systems this means that
  489.           the child    process    cannot outlive the parent.
  490.  
  491.       Signals
  492.           You'll have to catch the SIGCHLD signal, and possibly
  493.           SIGPIPE too.  SIGCHLD is sent when the backgrounded
  494.           process finishes.     SIGPIPE is sent when you write    to a
  495.           filehandle whose child process has closed    (an untrapped
  496.           SIGPIPE can cause    your program to    silently die).    This
  497.           is not an    issue with system("cmd&").
  498.  
  499.       Zombies
  500.           You have to be prepared to "reap"    the child process when
  501.           it finishes
  502.  
  503.           $SIG{CHLD} = sub { wait };
  504.  
  505.           See the section on _S_i_g_n_a_l_s in the    _p_e_r_l_i_p_c    manpage    for
  506.           other examples of    code to    do this.  Zombies are not an
  507.           issue with system("prog &").
  508.  
  509.       HHHHoooowwww ddddoooo IIII ttttrrrraaaapppp    ccccoooonnnnttttrrrroooollll    cccchhhhaaaarrrraaaacccctttteeeerrrrssss////ssssiiiiggggnnnnaaaallllssss????
  510.  
  511.       You don't actually "trap" a control character.  Instead,
  512.       that character generates a signal which is sent to your
  513.       terminal's currently foregrounded process group, which you
  514.       then trap in your process.  Signals are documented in    the
  515.       section on _S_i_g_n_a_l_s in    the _p_e_r_l_i_p_c manpage and    chapter    6 of
  516.       the Camel.
  517.  
  518.       Be warned that very few C libraries are re-entrant.
  519.       Therefore, if    you attempt to _p_r_i_n_t() in a handler that got
  520.       invoked during another stdio operation your internal
  521.       structures will likely be in an inconsistent state, and your
  522.  
  523.  
  524.  
  525.      Page 8                        (printed 10/23/98)
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.      PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))      5555////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))
  533.  
  534.  
  535.  
  536.       program will dump core.  You can sometimes avoid this    by
  537.       using    _s_y_s_w_r_i_t_e() instead of _p_r_i_n_t().
  538.  
  539.       Unless you're    exceedingly careful, the only safe things to
  540.       do inside a signal handler are: set a    variable and exit.
  541.       And in the first case, you should only set a variable    in
  542.       such a way that _m_a_l_l_o_c() is not called (eg, by setting a
  543.       variable that    already    has a value).
  544.  
  545.       For example:
  546.  
  547.           $Interrupted = 0;      # to ensure it has a value
  548.           $SIG{INT}    = sub {
  549.           $Interrupted++;
  550.           syswrite(STDERR, "ouch\n", 5);
  551.           }
  552.  
  553.       However, because syscalls restart by default,    you'll find
  554.       that if you're in a "slow" call, such    as <FH>, _r_e_a_d(),
  555.       _c_o_n_n_e_c_t(), or    _w_a_i_t(),    that the only way to terminate them is
  556.       by "longjumping" out;    that is, by raising an exception.  See
  557.       the time-out handler for a blocking _f_l_o_c_k() in the section
  558.       on _S_i_g_n_a_l_s in    the _p_e_r_l_i_p_c manpage or chapter 6 of the    Camel.
  559.  
  560.       HHHHoooowwww ddddoooo IIII mmmmooooddddiiiiffffyyyy tttthhhheeee sssshhhhaaaaddddoooowwww ppppaaaasssssssswwwwoooorrrrdddd ffffiiiilllleeee oooonnnn aaaa    UUUUnnnniiiixxxx ssssyyyysssstttteeeemmmm????
  561.  
  562.       If perl was installed    correctly, and your shadow library was
  563.       written properly, the    getpw*() functions described in    the
  564.       _p_e_r_l_f_u_n_c manpage should in theory provide (read-only)    access
  565.       to entries in    the shadow password file.  To change the file,
  566.       make a new shadow password file (the format varies from
  567.       system to system - see the _p_a_s_s_w_d(_5) manpage for specifics)
  568.       and use _p_w_d__m_k_d_b(8) to install it (see the _p_w_d__m_k_d_b(_5)
  569.       manpage for more details).
  570.  
  571.       HHHHoooowwww ddddoooo IIII sssseeeetttt tttthhhheeee ttttiiiimmmmeeee    aaaannnndddd ddddaaaatttteeee????
  572.  
  573.       Assuming you're running under    sufficient permissions,    you
  574.       should be able to set    the system-wide    date and time by
  575.       running the _d_a_t_e(1) program.    (There is no way to set    the
  576.       time and date    on a per-process basis.)  This mechanism will
  577.       work for Unix, MS-DOS, Windows, and NT; the VMS equivalent
  578.       is set time.
  579.  
  580.       However, if all you want to do is change your    timezone, you
  581.       can probably get away    with setting an    environment variable:
  582.  
  583.           $ENV{TZ} = "MST7MDT";             # unixish
  584.           $ENV{'SYS$TIMEZONE_DIFFERENTIAL'}="-5" # vms
  585.           system "trn comp.lang.perl.misc";
  586.  
  587.  
  588.  
  589.  
  590.  
  591.      Page 9                        (printed 10/23/98)
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.      PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))      5555////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))
  599.  
  600.  
  601.  
  602.       HHHHoooowwww ccccaaaannnn IIII _s_l_e_e_p() or _a_l_a_r_m() for under a second?
  603.  
  604.       If you want finer granularity    than the 1 second that the
  605.       _s_l_e_e_p() function provides, the easiest way is    to use the
  606.       _s_e_l_e_c_t() function as documented in the section on _s_e_l_e_c_t in
  607.       the _p_e_r_l_f_u_n_c manpage.     If your system    has itimers and
  608.       _s_y_s_c_a_l_l() support, you can check out the old example in
  609.       http://www.perl.com/CPAN/doc/misc/ancient/tutorial/eg/itimers.pl
  610.       .
  611.  
  612.       HHHHoooowwww ccccaaaannnn IIII mmmmeeeeaaaassssuuuurrrreeee ttttiiiimmmmeeee uuuunnnnddddeeeerrrr aaaa sssseeeeccccoooonnnndddd????
  613.  
  614.       In general, you may not be able to.  The Time::HiRes module
  615.       (available from CPAN)    provides this functionality for    some
  616.       systems.
  617.  
  618.       In general, you may not be able to.  But if your system
  619.       supports both    the _s_y_s_c_a_l_l() function in Perl as well as a
  620.       system call like _g_e_t_t_i_m_e_o_f_d_a_y(2), then you may be able to do
  621.       something like this:
  622.  
  623.           require 'sys/syscall.ph';
  624.  
  625.           $TIMEVAL_T = "LL";
  626.  
  627.           $done = $start = pack($TIMEVAL_T,    ());
  628.  
  629.           syscall( &SYS_gettimeofday, $start, 0)) != -1
  630.              or die    "gettimeofday: $!";
  631.  
  632.          ##########################
  633.          # DO YOUR OPERATION HERE #
  634.          ##########################
  635.  
  636.           syscall( &SYS_gettimeofday, $done, 0) != -1
  637.              or    die "gettimeofday: $!";
  638.  
  639.           @start = unpack($TIMEVAL_T, $start);
  640.           @done  = unpack($TIMEVAL_T, $done);
  641.  
  642.           #    fix microseconds
  643.           for ($done[1], $start[1])    { $_ /=    1_000_000 }
  644.  
  645.           $delta_time = sprintf "%.4f", ($done[0]  + $done[1]  )
  646.                               -
  647.                        ($start[0] +    $start[1] );
  648.  
  649.  
  650.       HHHHoooowwww ccccaaaannnn IIII ddddoooo aaaannnn _a_t_e_x_i_t() or _s_e_t_j_m_p()/_l_o_n_g_j_m_p()? (Exception
  651.       handling)
  652.  
  653.       Release 5 of Perl added the END block, which can be used to
  654.  
  655.  
  656.  
  657.      Page 10                        (printed 10/23/98)
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.      PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))      5555////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))
  665.  
  666.  
  667.  
  668.       simulate _a_t_e_x_i_t().  Each package's END block is called when
  669.       the program or thread    ends (see the _p_e_r_l_m_o_d manpage manpage
  670.       for more details).
  671.  
  672.       For example, you can use this    to make    sure your filter
  673.       program managed to finish its    output without filling up the
  674.       disk:
  675.  
  676.           END {
  677.           close(STDOUT)    || die "stdout close failed: $!";
  678.           }
  679.  
  680.       The END block    isn't called when untrapped signals kill the
  681.       program, though, so if you use END blocks you    should also
  682.       use
  683.  
  684.           use sigtrap qw(die normal-signals);
  685.  
  686.       Perl's exception-handling mechanism is its _e_v_a_l() operator.
  687.       You can use _e_v_a_l() as    setjmp and _d_i_e() as longjmp.  For
  688.       details of this, see the section on signals, especially the
  689.       time-out handler for a blocking _f_l_o_c_k() in the section on
  690.       _S_i_g_n_a_l_s in the _p_e_r_l_i_p_c manpage and chapter 6 of the Camel.
  691.  
  692.       If exception handling    is all you're interested in, try the
  693.       exceptions.pl    library    (part of the standard perl
  694.       distribution).
  695.  
  696.       If you want the _a_t_e_x_i_t() syntax (and an _r_m_e_x_i_t() as well),
  697.       try the AtExit module    available from CPAN.
  698.  
  699.       WWWWhhhhyyyy ddddooooeeeessssnnnn''''tttt mmmmyyyy ssssoooocccckkkkeeeettttssss pppprrrrooooggggrrrraaaammmm wwwwoooorrrrkkkk uuuunnnnddddeeeerrrr SSSSyyyysssstttteeeemmmm VVVV
  700.       ((((SSSSoooollllaaaarrrriiiissss))))???? WWWWhhhhaaaatttt ddddooooeeeessss tttthhhheeee eeeerrrrrrrroooorrrr mmmmeeeessssssssaaaaggggeeee """"PPPPrrrroooottttooooccccoooollll nnnnooootttt
  701.       ssssuuuuppppppppoooorrrrtttteeeedddd"""" mmmmeeeeaaaannnn????
  702.  
  703.       Some Sys-V based systems, notably Solaris 2.X, redefined
  704.       some of the standard socket constants.  Since    these were
  705.       constant across all architectures, they were often hardwired
  706.       into perl code.  The proper way to deal with this is to "use
  707.       Socket" to get the correct values.
  708.  
  709.       Note that even though    SunOS and Solaris are binary
  710.       compatible, these values are different.  Go figure.
  711.  
  712.       HHHHoooowwww ccccaaaannnn IIII ccccaaaallllllll mmmmyyyy ssssyyyysssstttteeeemmmm''''ssss uuuunnnniiiiqqqquuuueeee CCCC ffffuuuunnnnccccttttiiiioooonnnnssss    ffffrrrroooommmm PPPPeeeerrrrllll????
  713.  
  714.       In most cases, you write an external module to do it - see
  715.       the answer to    "Where can I learn about linking C with    Perl?
  716.       [h2xs, xsubpp]".  However, if    the function is    a system call,
  717.       and your system supports _s_y_s_c_a_l_l(), you can use the syscall
  718.       function (documented in the _p_e_r_l_f_u_n_c manpage).
  719.  
  720.  
  721.  
  722.  
  723.      Page 11                        (printed 10/23/98)
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.      PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))      5555////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))
  731.  
  732.  
  733.  
  734.       Remember to check the    modules    that came with your
  735.       distribution,    and CPAN as well - someone may already have
  736.       written a module to do it.
  737.  
  738.       WWWWhhhheeeerrrreeee    ddddoooo IIII ggggeeeetttt tttthhhheeee iiiinnnncccclllluuuuddddeeee ffffiiiilllleeeessss ttttoooo ddddoooo _i_o_c_t_l() or _s_y_s_c_a_l_l()?
  739.  
  740.       Historically,    these would be generated by the    h2ph tool,
  741.       part of the standard perl distribution.  This    program
  742.       converts _c_p_p(1) directives in    C header files to files
  743.       containing subroutine    definitions, like &SYS_getitimer,
  744.       which    you can    use as arguments to your functions.  It
  745.       doesn't work perfectly, but it usually gets most of the job
  746.       done.     Simple    files like _e_r_r_n_o._h, _s_y_s_c_a_l_l._h, and _s_o_c_k_e_t._h
  747.       were fine, but the hard ones like _i_o_c_t_l._h nearly always need
  748.       to hand-edited.  Here's how to install the *.ph files:
  749.  
  750.           1.  become super-user
  751.           2.  cd /usr/include
  752.           3.  h2ph *.h */*.h
  753.  
  754.       If your system supports dynamic loading, for reasons of
  755.       portability and sanity you probably ought to use h2xs    (also
  756.       part of the standard perl distribution).  This tool converts
  757.       C header files to Perl extensions.  See the _p_e_r_l_x_s_t_u_t
  758.       manpage for how to get started with h2xs.
  759.  
  760.       If your system doesn't support dynamic loading, you still
  761.       probably ought to use    h2xs.  See the _p_e_r_l_x_s_t_u_t manpage and
  762.       the _E_x_t_U_t_i_l_s::_M_a_k_e_M_a_k_e_r manpage for more information (in
  763.       brief, just use mmmmaaaakkkkeeee ppppeeeerrrrllll instead of a plain mmmmaaaakkkkeeee to rebuild
  764.       perl with a new static extension).
  765.  
  766.       WWWWhhhhyyyy ddddoooo sssseeeettttuuuuiiiidddd    ppppeeeerrrrllll ssssccccrrrriiiippppttttssss ccccoooommmmppppllllaaaaiiiinnnn aaaabbbboooouuuutttt kkkkeeeerrrrnnnneeeellll pppprrrroooobbbblllleeeemmmmssss????
  767.  
  768.       Some operating systems have bugs in the kernel that make
  769.       setuid scripts inherently insecure.  Perl gives you a    number
  770.       of options (described    in the _p_e_r_l_s_e_c manpage)    to work    around
  771.       such systems.
  772.  
  773.       HHHHoooowwww ccccaaaannnn IIII ooooppppeeeennnn aaaa ppppiiiippppeeee    bbbbooootttthhhh ttttoooo    aaaannnndddd ffffrrrroooommmm aaaa ccccoooommmmmmmmaaaannnndddd????
  774.  
  775.       The IPC::Open2 module    (part of the standard perl
  776.       distribution)    is an easy-to-use approach that    internally
  777.       uses _p_i_p_e(), _f_o_r_k(), and _e_x_e_c() to do    the job.  Make sure
  778.       you read the deadlock    warnings in its    documentation, though
  779.       (see the _I_P_C::_O_p_e_n_2 manpage).     See the section on
  780.       _B_i_d_i_r_e_c_t_i_o_n_a_l    _C_o_m_m_u_n_i_c_a_t_i_o_n _w_i_t_h _A_n_o_t_h_e_r _P_r_o_c_e_s_s in the
  781.       _p_e_r_l_i_p_c manpage and the section on _B_i_d_i_r_e_c_t_i_o_n_a_l
  782.       _C_o_m_m_u_n_i_c_a_t_i_o_n    _w_i_t_h _Y_o_u_r_s_e_l_f in the _p_e_r_l_i_p_c manpage
  783.  
  784.       You may also use the IPC::Open3 module (part of the standard
  785.       perl distribution), but be warned that it has    a different
  786.  
  787.  
  788.  
  789.      Page 12                        (printed 10/23/98)
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.      PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))      5555////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))
  797.  
  798.  
  799.  
  800.       order    of arguments from IPC::Open2 (see the _I_P_C::_O_p_e_n_3
  801.       manpage).
  802.  
  803.       WWWWhhhhyyyy ccccaaaannnn''''tttt IIII ggggeeeetttt tttthhhheeee oooouuuuttttppppuuuutttt ooooffff    aaaa ccccoooommmmmmmmaaaannnndddd wwwwiiiitttthhhh _s_y_s_t_e_m()?
  804.  
  805.       You're confusing the purpose of _s_y_s_t_e_m() and backticks (``).
  806.       _s_y_s_t_e_m() runs    a command and returns exit status information
  807.       (as a    16 bit value:  the low 7 bits are the signal the
  808.       process died from, if    any, and the high 8 bits are the
  809.       actual exit value).  Backticks (``) run a command and    return
  810.       what it sent to STDOUT.
  811.  
  812.           $exit_status   = system("mail-users");
  813.           $output_string = `ls`;
  814.  
  815.  
  816.       HHHHoooowwww ccccaaaannnn IIII ccccaaaappppttttuuuurrrreeee SSSSTTTTDDDDEEEERRRRRRRR ffffrrrroooommmm    aaaannnn eeeexxxxtttteeeerrrrnnnnaaaallll ccccoooommmmmmmmaaaannnndddd????
  817.  
  818.       There    are three basic    ways of    running    external commands:
  819.  
  820.           system $cmd;          # using system()
  821.           $output =    `$cmd`;          # using backticks (``)
  822.           open (PIPE, "cmd |");      # using open()
  823.  
  824.       With _s_y_s_t_e_m(), both STDOUT and STDERR    will go    the same place
  825.       as the script's versions of these, unless the    command
  826.       redirects them.  Backticks and _o_p_e_n()    read oooonnnnllllyyyy the STDOUT
  827.       of your command.
  828.  
  829.       With any of these, you can change file descriptors before
  830.       the call:
  831.  
  832.           open(STDOUT, ">logfile");
  833.           system("ls");
  834.  
  835.       or you can use Bourne    shell file-descriptor redirection:
  836.  
  837.           $output =    `$cmd 2>some_file`;
  838.           open (PIPE, "cmd 2>some_file |");
  839.  
  840.       You can also use file-descriptor redirection to make STDERR
  841.       a duplicate of STDOUT:
  842.  
  843.           $output =    `$cmd 2>&1`;
  844.           open (PIPE, "cmd 2>&1 |");
  845.  
  846.       Note that you    _c_a_n_n_o_t simply open STDERR to be    a dup of
  847.       STDOUT in your Perl program and avoid    calling    the shell to
  848.       do the redirection.  This doesn't work:
  849.  
  850.           open(STDERR, ">&STDOUT");
  851.           $alloutput = `cmd    args`;    # stderr still escapes
  852.  
  853.  
  854.  
  855.      Page 13                        (printed 10/23/98)
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.      PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))      5555////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))
  863.  
  864.  
  865.  
  866.       This fails because the _o_p_e_n()    makes STDERR go    to where
  867.       STDOUT was going at the time of the _o_p_e_n().  The backticks
  868.       then make STDOUT go to a string, but don't change STDERR
  869.       (which still goes to the old STDOUT).
  870.  
  871.       Note that you    _m_u_s_t use Bourne    shell (_s_h(1)) redirection
  872.       syntax in backticks, not _c_s_h(1)!  Details on why Perl's
  873.       _s_y_s_t_e_m() and backtick    and pipe opens all use the Bourne
  874.       shell    are in
  875.       http://www.perl.com/CPAN/doc/FMTEYEWTK/versus/csh.whynot .
  876.       To capture a command's STDERR    and STDOUT together:
  877.  
  878.           $output =    `cmd 2>&1`;              # either with    backticks
  879.           $pid = open(PH, "cmd 2>&1    |");          # or with an open pipe
  880.           while (<PH>) { }                  #    plus a read
  881.  
  882.       To capture a command's STDOUT    but discard its    STDERR:
  883.  
  884.           $output =    `cmd 2>/dev/null`;          # either with    backticks
  885.           $pid = open(PH, "cmd 2>/dev/null |");      # or with an open pipe
  886.           while (<PH>) { }                  #    plus a read
  887.  
  888.       To capture a command's STDERR    but discard its    STDOUT:
  889.  
  890.           $output =    `cmd 2>&1 1>/dev/null`;          # either with    backticks
  891.           $pid = open(PH, "cmd 2>&1    1>/dev/null |");  # or with an open pipe
  892.           while (<PH>) { }                  #    plus a read
  893.  
  894.       To exchange a    command's STDOUT and STDERR in order to
  895.       capture the STDERR but leave its STDOUT to come out our old
  896.       STDERR:
  897.  
  898.           $output =    `cmd 3>&1 1>&2 2>&3 3>&-`;      # either with    backticks
  899.           $pid = open(PH, "cmd 3>&1    1>&2 2>&3 3>&-|");# or with an open pipe
  900.           while (<PH>) { }                  #    plus a read
  901.  
  902.       To read both a command's STDOUT and its STDERR separately,
  903.       it's easiest and safest to redirect them separately to
  904.       files, and then read from those files    when the program is
  905.       done:
  906.  
  907.           system("program args 1>/tmp/program.stdout 2>/tmp/program.stderr");
  908.  
  909.       Ordering is important    in all these examples.    That's because
  910.       the shell processes file descriptor redirections in strictly
  911.       left to right    order.
  912.  
  913.           system("prog args    1>tmpfile 2>&1");
  914.           system("prog args    2>&1 1>tmpfile");
  915.  
  916.       The first command sends both standard    out and    standard error
  917.       to the temporary file.  The second command sends only    the
  918.  
  919.  
  920.  
  921.      Page 14                        (printed 10/23/98)
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.      PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))      5555////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))
  929.  
  930.  
  931.  
  932.       old standard output there, and the old standard error    shows
  933.       up on    the old    standard out.
  934.  
  935.       WWWWhhhhyyyy ddddooooeeeessssnnnn''''tttt _o_p_e_n() return an error when a pipe open fails?
  936.  
  937.       It does, but probably    not how    you expect it to.  On systems
  938.       that follow the standard _f_o_r_k()/_e_x_e_c() paradigm (such    as
  939.       Unix), it works like this: _o_p_e_n() causes a _f_o_r_k().  In the
  940.       parent, _o_p_e_n() returns with the process ID of    the child.
  941.       The child _e_x_e_c()s the    command    to be piped to/from.  The
  942.       parent can't know whether the    _e_x_e_c() was successful or not -
  943.       all it can return is whether the _f_o_r_k() succeeded or not.
  944.       To find out if the command succeeded,    you have to catch
  945.       SIGCHLD and _w_a_i_t() to    get the    exit status.  You should also
  946.       catch    SIGPIPE    if you're writing to the child -- you may not
  947.       have found out the _e_x_e_c() failed by the time you write.
  948.       This is documented in    the _p_e_r_l_i_p_c manpage.
  949.  
  950.       On systems that follow the _s_p_a_w_n() paradigm, _o_p_e_n() _m_i_g_h_t do
  951.       what you expect - unless perl    uses a shell to    start your
  952.       command. In this case    the _f_o_r_k()/_e_x_e_c() description still
  953.       applies.
  954.  
  955.       WWWWhhhhaaaatttt''''ssss wwwwrrrroooonnnngggg wwwwiiiitttthhhh uuuussssiiiinnnngggg bbbbaaaacccckkkkttttiiiicccckkkkssss iiiinnnn aaaa vvvvooooiiiidddd ccccoooonnnntttteeeexxxxtttt????
  956.  
  957.       Strictly speaking, nothing.  Stylistically speaking, it's
  958.       not a    good way to write maintainable code because backticks
  959.       have a (potentially humungous) return    value, and you're
  960.       ignoring it.    It's may also not be very efficient, because
  961.       you have to read in all the lines of output, allocate    memory
  962.       for them, and    then throw it away.  Too often people are
  963.       lulled to writing:
  964.  
  965.           `cp file file.bak`;
  966.  
  967.       And now they think "Hey, I'll    just always use    backticks to
  968.       run programs."  Bad idea: backticks are for capturing    a
  969.       program's output; the    _s_y_s_t_e_m() function is for running
  970.       programs.
  971.  
  972.       Consider this    line:
  973.  
  974.           `cat /etc/termcap`;
  975.  
  976.       You haven't assigned the output anywhere, so it just wastes
  977.       memory (for a    little while).    Plus you forgot    to check $? to
  978.       see whether the program even ran correctly.  Even if you
  979.       wrote
  980.  
  981.           print `cat /etc/termcap`;
  982.  
  983.       In most cases, this could and    probably should    be written as
  984.  
  985.  
  986.  
  987.      Page 15                        (printed 10/23/98)
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.      PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))      5555////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))
  995.  
  996.  
  997.  
  998.           system("cat /etc/termcap") == 0
  999.           or die "cat program failed!";
  1000.  
  1001.       Which    will get the output quickly (as    its generated, instead
  1002.       of only at the end) and also check the return    value.
  1003.  
  1004.       _s_y_s_t_e_m() also    provides direct    control    over whether shell
  1005.       wildcard processing may take place, whereas backticks    do
  1006.       not.
  1007.  
  1008.       HHHHoooowwww ccccaaaannnn IIII ccccaaaallllllll bbbbaaaacccckkkkttttiiiicccckkkkssss wwwwiiiitttthhhhoooouuuutttt sssshhhheeeellllllll pppprrrroooocccceeeessssssssiiiinnnngggg????
  1009.  
  1010.       This is a bit    tricky.     Instead of writing
  1011.  
  1012.           @ok = `grep @opts    '$search_string' @filenames`;
  1013.  
  1014.       You have to do this:
  1015.  
  1016.           my @ok = ();
  1017.           if (open(GREP, "-|")) {
  1018.           while    (<GREP>) {
  1019.               chomp;
  1020.               push(@ok,    $_);
  1021.           }
  1022.           close    GREP;
  1023.           }    else {
  1024.           exec 'grep', @opts, $search_string, @filenames;
  1025.           }
  1026.  
  1027.       Just as with _s_y_s_t_e_m(), no shell escapes happen when you
  1028.       _e_x_e_c() a list.
  1029.  
  1030.       There    are more examples of this the section on _S_a_f_e _P_i_p_e
  1031.       _O_p_e_n_s    in the _p_e_r_l_i_p_c manpage.
  1032.  
  1033.       WWWWhhhhyyyy ccccaaaannnn''''tttt mmmmyyyy ssssccccrrrriiiipppptttt rrrreeeeaaaadddd ffffrrrroooommmm    SSSSTTTTDDDDIIIINNNN aaaafffftttteeeerrrr IIII ggggaaaavvvveeee iiiitttt EEEEOOOOFFFF ((((^^^^DDDD
  1034.       oooonnnn UUUUnnnniiiixxxx,,,, ^^^^ZZZZ oooonnnn MMMMSSSS----DDDDOOOOSSSS))))????
  1035.  
  1036.       Because some stdio's set error and eof flags that need
  1037.       clearing.  The POSIX module defines _c_l_e_a_r_e_r_r() that you can
  1038.       use.    That is    the technically    correct    way to do it.  Here
  1039.       are some less    reliable workarounds:
  1040.  
  1041.       1   Try keeping around the seekpointer and go    there, like
  1042.           this:
  1043.  
  1044.           $where = tell(LOG);
  1045.           seek(LOG, $where, 0);
  1046.  
  1047.  
  1048.       2   If that doesn't work, try    seeking    to a different part of
  1049.           the file and then    back.
  1050.  
  1051.  
  1052.  
  1053.      Page 16                        (printed 10/23/98)
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.      PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))      5555////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))
  1061.  
  1062.  
  1063.  
  1064.       3   If that doesn't work, try    seeking    to a different part of
  1065.           the file,    reading    something, and then seeking back.
  1066.  
  1067.       4   If that doesn't work, give up on your stdio package and
  1068.           use sysread.
  1069.  
  1070.       HHHHoooowwww ccccaaaannnn IIII ccccoooonnnnvvvveeeerrrrtttt mmmmyyyy sssshhhheeeellllllll ssssccccrrrriiiipppptttt ttttoooo ppppeeeerrrrllll????
  1071.  
  1072.       Learn    Perl and rewrite it.  Seriously, there's no simple
  1073.       converter.  Things that are awkward to do in the shell are
  1074.       easy to do in    Perl, and this very awkwardness    is what    would
  1075.       make a shell->perl converter nigh-on impossible to write.
  1076.       By rewriting it, you'll think    about what you're really
  1077.       trying to do,    and hopefully will escape the shell's pipeline
  1078.       datastream paradigm, which while convenient for some
  1079.       matters, causes many inefficiencies.
  1080.  
  1081.       CCCCaaaannnn IIII    uuuusssseeee ppppeeeerrrrllll ttttoooo rrrruuuunnnn    aaaa tttteeeellllnnnneeeetttt oooorrrr ffffttttpppp    sssseeeessssssssiiiioooonnnn????
  1082.  
  1083.       Try the Net::FTP, TCP::Client, and Net::Telnet modules
  1084.       (available from CPAN).
  1085.       http://www.perl.com/CPAN/scripts/netstuff/telnet.emul.shar
  1086.       will also help for emulating the telnet protocol, but
  1087.       Net::Telnet is quite probably    easier to use..
  1088.  
  1089.       If all you want to do    is pretend to be telnet    but don't need
  1090.       the initial telnet handshaking, then the standard dual-
  1091.       process approach will    suffice:
  1092.  
  1093.           use IO::Socket;          # new    in 5.004
  1094.           $handle =    IO::Socket::INET->new('www.perl.com:80')
  1095.               || die "can't connect to port 80 on www.perl.com:    $!";
  1096.           $handle->autoflush(1);
  1097.           if (fork()) {          # XXX: undef means failure
  1098.           select($handle);
  1099.           print    while <STDIN>;      # everything from stdin to socket
  1100.           }    else {
  1101.           print    while <$handle>;  # everything from socket to stdout
  1102.           }
  1103.           close $handle;
  1104.           exit;
  1105.  
  1106.  
  1107.       HHHHoooowwww ccccaaaannnn IIII wwwwrrrriiiitttteeee eeeexxxxppppeeeecccctttt iiiinnnn PPPPeeeerrrrllll????
  1108.  
  1109.       Once upon a time, there was a    library    called chat2.pl    (part
  1110.       of the standard perl distribution), which never really got
  1111.       finished.  If    you find it somewhere, _d_o_n'_t _u_s_e _i_t.  These
  1112.       days,    your best bet is to look at the    Expect module
  1113.       available from CPAN, which also requires two other modules
  1114.       from CPAN, IO::Pty and IO::Stty.
  1115.  
  1116.  
  1117.  
  1118.  
  1119.      Page 17                        (printed 10/23/98)
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.      PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))      5555////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))
  1127.  
  1128.  
  1129.  
  1130.       IIIIssss tttthhhheeeerrrreeee aaaa wwwwaaaayyyy ttttoooo hhhhiiiiddddeeee ppppeeeerrrrllll''''ssss    ccccoooommmmmmmmaaaannnndddd    lllliiiinnnneeee ffffrrrroooommmm pppprrrrooooggggrrrraaaammmmssss
  1131.       ssssuuuucccchhhh aaaassss """"ppppssss""""????
  1132.  
  1133.       First    of all note that if you're doing this for security
  1134.       reasons (to avoid people seeing passwords, for example) then
  1135.       you should rewrite your program so that critical information
  1136.       is never given as an argument.  Hiding the arguments won't
  1137.       make your program completely secure.
  1138.  
  1139.       To actually alter the    visible    command    line, you can assign
  1140.       to the variable $0 as    documented in the _p_e_r_l_v_a_r manpage.
  1141.       This won't work on all operating systems, though.  Daemon
  1142.       programs like    sendmail place their state there, as in:
  1143.  
  1144.           $0 = "orcus [accepting connections]";
  1145.  
  1146.  
  1147.       IIII {{{{cccchhhhaaaannnnggggeeeedddd ddddiiiirrrreeeeccccttttoooorrrryyyy,,,,    mmmmooooddddiiiiffffiiiieeeedddd mmmmyyyy eeeennnnvvvviiiirrrroooonnnnmmmmeeeennnntttt}}}} iiiinnnn aaaa ppppeeeerrrrllll
  1148.       ssssccccrrrriiiipppptttt....  HHHHoooowwww ccccoooommmmeeee tttthhhheeee    cccchhhhaaaannnnggggeeee ddddiiiissssaaaappppppppeeeeaaaarrrreeeedddd wwwwhhhheeeennnn    IIII eeeexxxxiiiitttteeeedddd tttthhhheeee
  1149.       ssssccccrrrriiiipppptttt????  HHHHoooowwww ddddoooo IIII ggggeeeetttt    mmmmyyyy cccchhhhaaaannnnggggeeeessss ttttoooo bbbbeeee vvvviiiissssiiiibbbblllleeee????
  1150.  
  1151.       Unix
  1152.           In the strictest sense, it can't be done -- the script
  1153.           executes as a different process from the shell it    was
  1154.           started from.  Changes to    a process are not reflected in
  1155.           its parent, only in its own children created after the
  1156.           change.  There is    shell magic that may allow you to fake
  1157.           it by _e_v_a_l()ing the script's output in your shell; check
  1158.           out the comp.unix.questions FAQ for details.
  1159.  
  1160.       HHHHoooowwww ddddoooo IIII cccclllloooosssseeee aaaa pppprrrroooocccceeeessssssss''''ssss ffffiiiilllleeeehhhhaaaannnnddddlllleeee    wwwwiiiitttthhhhoooouuuutttt    wwwwaaaaiiiittttiiiinnnngggg    ffffoooorrrr iiiitttt
  1161.       ttttoooo ccccoooommmmpppplllleeeetttteeee????
  1162.  
  1163.       Assuming your    system supports    such things, just send an
  1164.       appropriate signal to    the process (see the section on    _k_i_l_l
  1165.       in the _p_e_r_l_f_u_n_c manpage.  It's common    to first send a    TERM
  1166.       signal, wait a little    bit, and then send a KILL signal to
  1167.       finish it off.
  1168.  
  1169.       HHHHoooowwww ddddoooo IIII ffffoooorrrrkkkk    aaaa ddddaaaaeeeemmmmoooonnnn pppprrrroooocccceeeessssssss????
  1170.  
  1171.       If by    daemon process you mean    one that's detached
  1172.       (disassociated from its tty),    then the following process is
  1173.       reported to work on most Unixish systems.  Non-Unix users
  1174.       should check their Your_OS::Process module for other
  1175.       solutions.
  1176.  
  1177.       +o   Open /dev/tty and    use the    the TIOCNOTTY ioctl on it.
  1178.           See the _t_t_y(_4) manpage for details.  Or better yet, you
  1179.           can just use the _P_O_S_I_X::_s_e_t_s_i_d() function, so you    don't
  1180.           have to worry about process groups.
  1181.  
  1182.  
  1183.  
  1184.  
  1185.      Page 18                        (printed 10/23/98)
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.      PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))      5555////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))
  1193.  
  1194.  
  1195.  
  1196.       +o   Change directory to /
  1197.  
  1198.       +o   Reopen STDIN, STDOUT, and    STDERR so they're not
  1199.           connected    to the old tty.
  1200.  
  1201.       +o   Background yourself like this:
  1202.  
  1203.           fork && exit;
  1204.  
  1205.  
  1206.       HHHHoooowwww ddddoooo IIII mmmmaaaakkkkeeee    mmmmyyyy pppprrrrooooggggrrrraaaammmm rrrruuuunnnn wwwwiiiitttthhhh sssshhhh aaaannnndddd ccccsssshhhh????
  1207.  
  1208.       See the _e_g/_n_i_h script    (part of the perl source
  1209.       distribution).
  1210.  
  1211.       HHHHoooowwww ddddoooo IIII ffffiiiinnnndddd    oooouuuutttt iiiiffff IIII''''mmmm rrrruuuunnnnnnnniiiinnnngggg iiiinnnntttteeeerrrraaaaccccttttiiiivvvveeeellllyyyy oooorrrr nnnnooootttt????
  1212.  
  1213.       Good question.  Sometimes -t STDIN and -t STDOUT can give
  1214.       clues, sometimes not.
  1215.  
  1216.           if (-t STDIN && -t STDOUT) {
  1217.           print    "Now what? ";
  1218.           }
  1219.  
  1220.       On POSIX systems, you    can test whether your own process
  1221.       group    matches    the current process group of your controlling
  1222.       terminal as follows:
  1223.  
  1224.           use POSIX    qw/getpgrp tcgetpgrp/;
  1225.           open(TTY,    "/dev/tty") or die $!;
  1226.           $tpgrp = tcgetpgrp(TTY);
  1227.           $pgrp = getpgrp();
  1228.           if ($tpgrp == $pgrp) {
  1229.           print    "foreground\n";
  1230.           }    else {
  1231.           print    "background\n";
  1232.           }
  1233.  
  1234.  
  1235.       HHHHoooowwww ddddoooo IIII ttttiiiimmmmeeeeoooouuuutttt aaaa sssslllloooowwww eeeevvvveeeennnntttt????
  1236.  
  1237.       Use the _a_l_a_r_m() function, probably in    conjunction with a
  1238.       signal handler, as documented    the section on _S_i_g_n_a_l_s in the
  1239.       _p_e_r_l_i_p_c manpage and chapter 6    of the Camel.  You may instead
  1240.       use the more flexible    Sys::AlarmCall module available    from
  1241.       CPAN.
  1242.  
  1243.       HHHHoooowwww ddddoooo IIII sssseeeetttt CCCCPPPPUUUU lllliiiimmmmiiiittttssss????
  1244.  
  1245.       Use the BSD::Resource    module from CPAN.
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.      Page 19                        (printed 10/23/98)
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.      PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))      5555////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))
  1259.  
  1260.  
  1261.  
  1262.       HHHHoooowwww ddddoooo IIII aaaavvvvooooiiiidddd zzzzoooommmmbbbbiiiieeeessss oooonnnn aaaa UUUUnnnniiiixxxx ssssyyyysssstttteeeemmmm????
  1263.  
  1264.       Use the reaper code from the section on _S_i_g_n_a_l_s in the
  1265.       _p_e_r_l_i_p_c manpage to call _w_a_i_t() when a    SIGCHLD    is received,
  1266.       or else use the double-fork technique    described in the fork
  1267.       entry    in the _p_e_r_l_f_u_n_c    manpage.
  1268.  
  1269.       HHHHoooowwww ddddoooo IIII uuuusssseeee aaaannnn SSSSQQQQLLLL ddddaaaattttaaaabbbbaaaasssseeee????
  1270.  
  1271.       There    are a number of    excellent interfaces to    SQL databases.
  1272.       See the DBD::* modules available from
  1273.       http://www.perl.com/CPAN/modules/dbperl/DBD .     A lot of
  1274.       information on this can be found at
  1275.       http://www.hermetica.com/technologia/perl/DBI/index.html .
  1276.  
  1277.       HHHHoooowwww ddddoooo IIII mmmmaaaakkkkeeee    aaaa _s_y_s_t_e_m() exit    on control-C?
  1278.  
  1279.       You can't.  You need to imitate the _s_y_s_t_e_m() call (see the
  1280.       _p_e_r_l_i_p_c manpage for sample code) and then have a signal
  1281.       handler for the INT signal that passes the signal on to the
  1282.       subprocess.  Or you can check    for it:
  1283.  
  1284.           $rc = system($cmd);
  1285.           if ($rc &    127) { die "signal death" }
  1286.  
  1287.  
  1288.       HHHHoooowwww ddddoooo IIII ooooppppeeeennnn    aaaa ffffiiiilllleeee wwwwiiiitttthhhhoooouuuutttt bbbblllloooocccckkkkiiiinnnngggg????
  1289.  
  1290.       If you're lucky enough to be using a system that supports
  1291.       non-blocking reads (most Unixish systems do),    you need only
  1292.       to use the O_NDELAY or O_NONBLOCK flag from the Fcntl    module
  1293.       in conjunction with _s_y_s_o_p_e_n():
  1294.  
  1295.           use Fcntl;
  1296.           sysopen(FH, "/tmp/somefile", O_WRONLY|O_NDELAY|O_CREAT, 0644)
  1297.           or die "can't    open /tmp/somefile: $!":
  1298.  
  1299.  
  1300.       HHHHoooowwww ddddoooo IIII iiiinnnnssssttttaaaallllllll aaaa CCCCPPPPAAAANNNN mmmmoooodddduuuulllleeee????
  1301.  
  1302.       The easiest way is to    have the CPAN module do    it for you.
  1303.       This module comes with perl version 5.004 and    later.    To
  1304.       manually install the CPAN module, or any well-behaved    CPAN
  1305.       module for that matter, follow these steps:
  1306.  
  1307.       1   Unpack the source    into a temporary area.
  1308.  
  1309.       2
  1310.  
  1311.           perl Makefile.PL
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.      Page 20                        (printed 10/23/98)
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.      PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))      5555////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))
  1325.  
  1326.  
  1327.  
  1328.       3
  1329.  
  1330.           make
  1331.  
  1332.  
  1333.       4
  1334.  
  1335.           make test
  1336.  
  1337.  
  1338.       5
  1339.  
  1340.           make install
  1341.  
  1342.  
  1343.       If your version of perl is compiled without dynamic loading,
  1344.       then you just    need to    replace    step 3 (mmmmaaaakkkkeeee) with mmmmaaaakkkkeeee    ppppeeeerrrrllll
  1345.       and you will get a new _p_e_r_l binary with your extension
  1346.       linked in.
  1347.  
  1348.       See the _E_x_t_U_t_i_l_s::_M_a_k_e_M_a_k_e_r manpage for more details on
  1349.       building extensions.    See also the next question.
  1350.  
  1351.       WWWWhhhhaaaatttt''''ssss tttthhhheeee ddddiiiiffffffffeeeerrrreeeennnncccceeee    bbbbeeeettttwwwweeeeeeeennnn    rrrreeeeqqqquuuuiiiirrrreeee    aaaannnndddd uuuusssseeee????
  1352.  
  1353.       Perl offers several different    ways to    include    code from one
  1354.       file into another.  Here are the deltas between the various
  1355.       inclusion constructs:
  1356.  
  1357.           1)  do $file is like eval    `cat $file`, except the    former:
  1358.           1.1: searches    @INC and updates %INC.
  1359.           1.2: bequeaths an *unrelated*    lexical    scope on the eval'ed code.
  1360.  
  1361.           2)  require $file    is like    do $file, except the former:
  1362.           2.1: checks for redundant loading, skipping already loaded files.
  1363.           2.2: raises an exception on failure to find, compile,    or execute $file.
  1364.  
  1365.           3)  require Module is like require "Module.pm", except the former:
  1366.           3.1: translates each "::" into your system's directory separator.
  1367.           3.2: primes the parser to disambiguate class Module as an indirect object.
  1368.  
  1369.           4)  use Module is    like require Module, except the    former:
  1370.           4.1: loads the module    at compile time, not run-time.
  1371.           4.2: imports symbols and semantics from that package to the current one.
  1372.  
  1373.       In general, you usually want use and a proper    Perl module.
  1374.  
  1375.       HHHHoooowwww ddddoooo IIII kkkkeeeeeeeepppp    mmmmyyyy oooowwwwnnnn mmmmoooodddduuuulllleeee////lllliiiibbbbrrrraaaarrrryyyy ddddiiiirrrreeeeccccttttoooorrrryyyy????
  1376.  
  1377.       When you build modules, use the PREFIX option    when
  1378.       generating Makefiles:
  1379.  
  1380.  
  1381.  
  1382.  
  1383.      Page 21                        (printed 10/23/98)
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.      PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))      5555////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))
  1391.  
  1392.  
  1393.  
  1394.           perl Makefile.PL PREFIX=/u/mydir/perl
  1395.  
  1396.       then either set the PERL5LIB environment variable before you
  1397.       run scripts that use the modules/libraries (see the _p_e_r_l_r_u_n
  1398.       manpage) or say
  1399.  
  1400.           use lib '/u/mydir/perl';
  1401.  
  1402.       See Perl's the _l_i_b manpage for more information.
  1403.  
  1404.       HHHHoooowwww ddddoooo IIII aaaadddddddd tttthhhheeee ddddiiiirrrreeeeccccttttoooorrrryyyy mmmmyyyy    pppprrrrooooggggrrrraaaammmm    lllliiiivvvveeeessss iiiinnnn ttttoooo tttthhhheeee
  1405.       mmmmoooodddduuuulllleeee////lllliiiibbbbrrrraaaarrrryyyy sssseeeeaaaarrrrcccchhhh    ppppaaaatttthhhh????
  1406.  
  1407.           use FindBin;
  1408.           use lib "$FindBin::Bin";
  1409.           use your_own_modules;
  1410.  
  1411.  
  1412.       HHHHoooowwww ddddoooo IIII aaaadddddddd aaaa ddddiiiirrrreeeeccccttttoooorrrryyyy ttttoooo mmmmyyyy iiiinnnncccclllluuuuddddeeee ppppaaaatttthhhh aaaatttt rrrruuuunnnnttttiiiimmmmeeee????
  1413.  
  1414.       Here are the suggested ways of modifying your    include    path:
  1415.  
  1416.           the PERLLIB environment variable
  1417.           the PERL5LIB environment variable
  1418.           the perl -Idir commpand line flag
  1419.           the use lib pragma, as in
  1420.           use lib "$ENV{HOME}/myown_perllib";
  1421.  
  1422.       The latter is    particularly useful because it knows about
  1423.       machine dependent architectures.  The    lib.pm pragmatic
  1424.       module was first included with the 5.002 release of Perl.
  1425.  
  1426.      AAAAUUUUTTTTHHHHOOOORRRR AAAANNNNDDDD    CCCCOOOOPPPPYYYYRRRRIIIIGGGGHHHHTTTT
  1427.       Copyright (c)    1997, 1998 Tom Christiansen and    Nathan
  1428.       Torkington.  All rights reserved.
  1429.  
  1430.       When included    as part    of the Standard    Version    of Perl, or as
  1431.       part of its complete documentation whether printed or
  1432.       otherwise, this work may be distributed only under the terms
  1433.       of Perl's Artistic License.  Any distribution    of this    file
  1434.       or derivatives thereof _o_u_t_s_i_d_e of that package require that
  1435.       special arrangements be made with copyright holder.
  1436.  
  1437.       Irrespective of its distribution, all    code examples in this
  1438.       file are hereby placed into the public domain.  You are
  1439.       permitted and    encouraged to use this code in your own
  1440.       programs for fun or for profit as you    see fit.  A simple
  1441.       comment in the code giving credit would be courteous but is
  1442.       not required.
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.      Page 22                        (printed 10/23/98)
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.      PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))      5555////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFAAAAQQQQ8888((((1111))))
  1457.  
  1458.  
  1459.  
  1460.  
  1461.  
  1462.  
  1463.  
  1464.  
  1465.  
  1466.  
  1467.  
  1468.  
  1469.  
  1470.  
  1471.  
  1472.  
  1473.  
  1474.  
  1475.  
  1476.  
  1477.  
  1478.  
  1479.  
  1480.  
  1481.  
  1482.  
  1483.  
  1484.  
  1485.  
  1486.  
  1487.  
  1488.  
  1489.  
  1490.  
  1491.  
  1492.  
  1493.  
  1494.  
  1495.  
  1496.  
  1497.  
  1498.  
  1499.  
  1500.  
  1501.  
  1502.  
  1503.  
  1504.  
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.      Page 23                        (printed 10/23/98)
  1513.  
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  
  1519.